<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script src="{{ getAssets }}js/jquery.table2excel.min.js?v={{ assets_version }}"></script>
<script>
$('a[data-typeid="20"]').addClass("am-btn-primary");
var queryParams = {};
var tables = $('#dataTables').DataTable({
    "sAjaxSource" : '{{ urlfor "GspController.Quality"}}'
    ,"bLengthChange": false
    ,"fnServerData" : function(sSource, aoData, fnCallback) {
        queryParams = checkQueryTableData(aoData);
        var form = $('.query-form').serializeArray();
        $.each(form, function(i, value){
            if(value.name == 'typeid') {
                queryParams[value.name] = Number(value.value);
            } else {
                queryParams[value.name] = value.value;
            }
        });
        $.post(sSource, JSON.stringify(queryParams),function(resp) {
            isLoading = true;
            fnCallback(resp);
        },'json')
    }
    ,order:[]
    ,columns: [
        {render:function(data, type, full, meta) {
                return productTypeidName(full.Products.TypeId);
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
            return full.Products.BrandName;
        }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.Name;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.ColourNumber;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.Spec;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.CastAway;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.ShelfLife;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.RegistrationId;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.Unit;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.Manufacturer;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.Products.ProducingArea;
            }, "bSortable": false}

        ,{render:function(data, type, full, meta) {
                return full.created_by;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return timetransDate(full.created_at);
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.updated_by;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.updated_at ? timetransDate(full.updated_at): '';
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.test_standard;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.test_situation;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.test_lable;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.appearance_quality;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.packing_situation;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.quality_situation;
            }, "bSortable": false}
        ,{render:function(data, type, full, meta) {
                return full.quality_standard_change;
            }, "bSortable": false}
        ,{
            "mDataProp": "Action",
            "bSortable": false,
            "sWidth":"8%",
            "render": function ( data, type, full, meta ) {
                btns = '<a href="javascript:;" class="am-btn am-btn-success am-btn-xs" onclick="edit('+ full.Id +');return false">修改</a>';
                return btns;
            }
        }
    ]
    ,"aLengthMenu":[20, 50, 100, 200]
	,'bLengthChange': true
    ,"serverSide": true
    ,"bPaginate" : true
    ,"bFilter" : false	//是否启动过滤、搜索功能
    ,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
    ,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示
});

$("#query-submit").bind("click", function () { //点击按钮 触发table重新请求服务器
    $("#dataTables").dataTable().fnDraw(false);
    return false;
});

function dialogCallBack() {
    $("#query-submit").click();
    layer.closeAll();
}

$('#insert-quality').click(function(){
    var url = '{{urlfor "GspController.QualityInsert"}}';

    layer.open({
        type: 2,
        title: '新增档案',
        shadeClose: false,
        shade: 0.2,
        maxmin: false,
        shift: 1,
        area: ['960px', '680px'],
        content: url
    });
    return false;
});

function edit(id){
    var url = '{{urlfor "GspController.QualityUpdate"}}/'+id;

    layer.open({
        type: 2,
        title: '修改档案',
        shadeClose: false,
        shade: 0.2,
        maxmin: false,
        shift: 1,
        area: ['960px', '680px'],
        content: url
    });
    return false;
}

var isLoading = false;
$('#download').bind("click", function(){
    if(isLoading) {
        $("#dataTables").table2excel({

            exclude: ".noExl",

            name: "导出器械类档案表",

            filename: "器械类档案表",

            fileext: ".xls",

            exclude_img: false,

            exclude_links: false,

            exclude_inputs: false
        });
    } else {
        $("#searchsubmit").click();
        layer.msg("还没加载结束请耐心等待一下！");return false;
    }
    return false;
});
</script>